package com.itheima.类加载与反射.反射.案例二;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class 反射实现 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        ClassLoader cl = ClassLoader.getSystemClassLoader();
        InputStream input = cl.getResourceAsStream("prop.properties");
        Properties prop = new Properties();
        prop.load(input);
        Class cla=Class.forName(prop.getProperty("className"));
        Constructor constructor = cla.getConstructor();
        Student stu = (Student)constructor.newInstance();
        Method method = cla.getMethod(prop.getProperty("method"));
        System.out.println(method.invoke(stu));

        input.close();
    }
}
